#ifndef NETWORKSERVERCONNECTION_H
#define NETWORKSERVERCONNECTION_H

#include <boost/thread.hpp>

#include "IConnection.h"
#include "network/ServerSession.h"

namespace ENE
{

class EventEngine;

class NetworkServerConnection : public IConnection
{
public:
	NetworkServerConnection(const UInt16& port);

	//Ecoute une connection
	void listen();

	//Demarre la partie reseau de la connection
	void start();

	//Envoie un evenement au server local ou distant
	void sendEvent(boost::shared_ptr<const IGameEvent> event);

	//Definit le moteur d'evenement
	void setEventEngine(boost::shared_ptr<EventEngine> eventEngine);

	//!Retourne l'id de la connection
	Int8 getId() const;
private:

	//Accepte un client
	void handleAccept(const boost::system::error_code& error, boost::shared_ptr<SocketConnection> conn);
	//Premiere communication avec le client
	void handleEventRead(const boost::system::error_code& error, const std::vector<Int8>& data, Int8 clientId);

	boost::asio::io_service m_ioService;
	ServerSession m_networkSession;
	boost::thread m_serviceThread;
	boost::shared_ptr<EventEngine> m_eventEngine;
};

}//namespace ENE

#endif

